﻿using System;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
using DevExpress.Xpo;

namespace Positive.Module.Common.Product
{
    [DefaultClassOptions]
    public class UnitOfMeasure : BaseObject
    {
        public UnitOfMeasure(Session session)
            : base(session)
        {
        }
        public override void AfterConstruction()
        {
            base.AfterConstruction();
            _isActive = true;
            _isDefault = false;
        }

        private string _name;
        private string _tag;
        private string _code;
        private double _factor;
        private UnitOfMeasureType _type;
        private bool _isActive;
        private bool _isDefault;

        [RuleRequiredField("UnitOfMeasure_Name", DefaultContexts.Save)]
        public string Name
        {
            get
            {
                return _name;
            }
            set
            {
                SetPropertyValue("Name", ref _name, value);
            }
        }

        public string Tag
        {
            get
            {
                return _tag;
            }
            set
            {
                SetPropertyValue("Tag", ref _tag, value);
            }
        }


        [Indexed(Unique = true)]
        [RuleRequiredField("UnitOfMeasure_Code", DefaultContexts.Save)]
        public string Code
        {
            get
            {
                return _code;
            }
            set
            {
                SetPropertyValue("Code", ref _code, value);
            }
        }

        public double Factor
        {
            get
            {
                return _factor;
            }
            set
            {
                SetPropertyValue("Factor", ref _factor, value);
            }
        }

        public bool IsActive
        {
            get
            {
                return _isActive;
            }
            set
            {
                SetPropertyValue("IsActive", ref _isActive, value);
            }
        }


        public bool IsDefault
        {
            get
            {
                return _isDefault;
            }
            set
            {
                SetPropertyValue("IsDefault", ref _isDefault, value);
            }
        }

        [Association("UnitOfMeasureType-UnitOfMeasure")]
        public UnitOfMeasureType Type
        {
            get
            {
                return _type;
            }
            set
            {
                SetPropertyValue ("Type", ref _type, value );
            }
        }
    }
}
